package com.clinic.action.schedule;

import java.util.Calendar;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.clinic.action.common.AbstractAction;
import com.clinic.entity.gui.GuiAppointment;
import com.clinic.entity.gui.GuiPatient;
import com.clinic.entity.type.AppointmentTime;
import com.clinic.logic.appointment.AppointmentLogic;
import com.clinic.logic.user.PatientLogic;
import com.clinic.util.CommonUtil;

public class ScheduleAction extends AbstractAction {

	private static final long serialVersionUID = 568747665427831022L;
	
	@Autowired
	private PatientLogic patientLogic;
	
	@Autowired
	private AppointmentLogic appointmentLogic;
	
	private GuiAppointment guiAppointment;
	private List<GuiAppointment> guiAppointmentList;
	private long patientId;
	private long id;
	private String aptDate;
	
	public String registration() {
		if(patientId > 0){
			GuiPatient guiPatient = patientLogic.getPatientDetailsById(patientId);
			guiAppointment = appointmentLogic.getPatientAppointmentByPatient(guiPatient);
		}else if(id > 0){
			guiAppointment = appointmentLogic.getAppointmentDetailsById(id);
		}
        if (StringUtils.isNotBlank(aptDate)) {
        	guiAppointmentList = appointmentLogic.getDayAppointmentListByDate(CommonUtil.getDateByStringFormat(aptDate));
        } else {
        	Calendar cal = Calendar.getInstance();
        	guiAppointmentList = appointmentLogic.getDayAppointmentListByDate(cal.getTime());
        }		
		
		return ActionResult.SUCCESS;
	}
	
	public String show(){
		return ActionResult.SUCCESS;
	}

	public String edit(){
		guiAppointment = appointmentLogic.getAppointmentDetailsById(id);
		return ActionResult.SUCCESS;
	}

	public String delete(){
		return ActionResult.SUCCESS;
	}
	
	public String insert() {
		guiAppointment = appointmentLogic.insertAppointment(guiAppointment);
		return ActionResult.SUCCESS;
	}

	public String update(){
		guiAppointment = appointmentLogic.updateAppointment(guiAppointment);
		return ActionResult.SUCCESS;
	}
	
	/*public List<String> getAppointmentTimes() {
		return AppointmentTime.getLabelList();
	}*/
	
	public AppointmentTime[] getAppointmentTimes() {
		return AppointmentTime.values();
	}

	public GuiAppointment getGuiAppointment() {
		return guiAppointment;
	}

	public void setGuiAppointment(GuiAppointment guiAppointment) {
		this.guiAppointment = guiAppointment;
	}

	public long getPatientId() {
		return patientId;
	}

	public void setPatientId(long patientId) {
		this.patientId = patientId;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getAptDate() {
		return aptDate;
	}

	public void setAptDate(String aptDate) {
		this.aptDate = aptDate;
	}

	public List<GuiAppointment> getGuiAppointmentList() {
		return guiAppointmentList;
	}

	public void setGuiAppointmentList(List<GuiAppointment> guiAppointmentList) {
		this.guiAppointmentList = guiAppointmentList;
	}

	
}
